import base64
from PIL import Image
import io

def image_to_base64(image_path):
    """
    将图片文件转换为Base64编码的字符串

    :param image_path: 图片文件的路径
    :return: Base64编码的字符串
    """
    # 打开图片文件
    with Image.open(image_path) as img:
        # 将图片转换为字节流
        buffered = io.BytesIO()
        img.save(buffered, format="PNG")  # 使用PNG格式保存图片，可以根据需要更改为其他格式
        img_str = base64.b64encode(buffered.getvalue()).decode('utf-8')

    return img_str

# 示例使用
if __name__ == "__main__":
    image_path = "/images/2025-01-24_11_44_19_董晓芳_打卡照片.jpg"  # 替换为你的图片路径
    base64_string = image_to_base64(image_path)
    print(base64_string)